<template>
  <div class="item-view">
    <div class="content">
      <div class="tip" :style="{ backgroundColor: NETWORKCARD_BG_COLOR[data.type] }">
        {{ NETWORKCARD_NAME[data.type] }}
      </div>
      <div class="info">
        <t-form ref="form" :data="formData" :colon="true" @submit="onSubmit"> </t-form>
        <div class="physical" v-if="data.type === 1">
          <div class="item">
            <div class="label">连接状态</div>
            <div class="value">
              <svg-icon class="item-icon" v-if="data.connect_status" name="item-open"></svg-icon>
              <svg-icon
                class="item-icon"
                style="width: 12px; height: 12px; margin-right: 6px"
                v-else
                name="item-error"
              ></svg-icon>
              <span>{{ data.connect_status ? '连接成功' : '连接失败' }}</span>
            </div>
          </div>
          <div class="item">
            <div class="label">连接类型</div>
            <div class="value">
              <t-form-item name="gender">
                <t-radio-group v-model="formData.connect_type">
                  <t-radio :value="1">动态连接</t-radio>
                  <t-radio :value="2">静态连接</t-radio>
                </t-radio-group>
              </t-form-item>
            </div>
          </div>
          <div class="item">
            <div class="label">IPV4地址</div>
            <div class="value">{{ data.ipv4 }}</div>
          </div>
          <div class="item">
            <div class="label">子网掩码</div>
            <div class="value">{{ data.subnet }}</div>
          </div>
          <div class="item">
            <div class="label">默认网关</div>
            <div class="value">{{ data.default }}</div>
          </div>
          <div class="item">
            <div class="label">DNS</div>
            <div class="value">{{ data.dns }}</div>
          </div>
        </div>
        <div class="fictitious" v-if="data.type === 2">
          <div class="common-item-view">
            <form-item :form-data="formData" v-for="(item, index) in FORM_INIT" :key="index" :data="item">
              <!-- <template #self_name>
                <t-input></t-input>
              </template> -->
            </form-item>
          </div>
        </div>
        <!-- <div v-for="(item, index) in list" :key="index" class="item">
          <svg-icon class="item-icon" :name="item.icon"></svg-icon>
          <div class="value">{{ item.value }}</div>
        </div> -->
      </div>
    </div>
    <div class="footer">
      <svg-icon class="time-icon" name="item-preserve"></svg-icon>
      <t-link theme="primary" style="margin-left: 8px; font-size: 11px; line-height: 14px" underline>保存</t-link>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, computed } from 'vue';
import { NETWORKCARD_NAME, NETWORKCARD_BG_COLOR } from '@/constants/data';

const props = defineProps({
  data: {
    type: Object as any,
    default: () => {
      return {};
    },
  },
});

const emits = defineEmits(['detail']);

const list = ref([
  { icon: 'item-user', value: '陌生人', key: 'user' },
  { icon: 'item-rate', value: '76.5%', key: 'rate' },
  { icon: 'item-position', value: '四川省成都市武侯区佳灵路323号', key: 'position' },
]);

const formData: any = ref({});
const FORM_INIT = computed(() => [
  { label: '启用禁用', value: formData.value.open, key: 'open', type: 'SwitchView' },
  { label: '链接状态', value: false, key: 'connect_status', type: 'SwitchView' },
  { label: 'IPV4地址', value: '', key: 'ipv4', type: 'IPAddressView', placeholder: '', disabled: !formData.value.open },
  {
    label: '子网掩码',
    value: '',
    key: 'subnet',
    type: 'IPAddressView',
    placeholder: '',
    disabled: !formData.value.open,
  },
  {
    label: '默认网关',
    value: '',
    key: 'default',
    type: 'IPAddressView',
    placeholder: '',
    disabled: !formData.value.open,
  },
  { label: 'DNS', value: '', key: 'dns', type: 'IPAddressView', placeholder: '', disabled: !formData.value.open },
]);

const onSubmit = (values: any) => {};
const clickDownload = () => {
  emits('detail', props.data);
};
onMounted(() => {
  if (props.data) {
    if (props.data.type === 1) {
      formData.value = {
        connect_type: 1,
        connect_status: false,
        ipv4: '192.168.4.64',
        subnet: '255.255.255.0',
        default: '192.168.2.1',
        dns: '192.168.2.1',
      };
    } else {
      formData.value = {
        open: props.data.open,
        connect_type: 1,
        connect_status: false,
        ipv4: '192.168.4.64',
        subnet: '255.255.255.0',
        default: '192.168.2.1',
        dns: '192.168.2.1',
      };
    }
  }
});
</script>

<style lang="less" scoped>
.item-view {
  width: 100%;
  background: #fff;
  border-radius: 6px;
  border: 1px solid #e9e9e9;
  padding: 0 12px;
  cursor: pointer;
  box-shadow: 3px 22px 50px -2px rgb(121 120 130 / 15%);
  position: relative;

  .content {
    width: 100%;
    height: calc(100% - 48px);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    box-sizing: border-box;
    border-bottom: 1px solid #c6ced9;
    .tip {
      width: 109px;
      height: 28px;
      font-size: 10px;
      text-align: center;
      line-height: 28px;
      border-radius: 5px 0px 120px 0px;
      color: #fff;
      position: absolute;
      top: 0;
      left: 0;
    }

    .face-icon {
      height: 100%;
    }

    .info {
      width: 100%;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      padding: 30px 0 2px;
      gap: 10px;

      .item {
        display: flex;
        align-items: center;
        gap: 6px;
        margin-bottom: 8px;
        .label {
          width: 70px;
          text-align: end;
        }

        .value {
          font-size: 12px;
          line-height: 16px;
          color: #2d3748;
          margin-left: 14px;
          display: flex;
          align-items: center;
          .item-icon {
            width: 16px;
            height: 16px;
            margin-right: 4px;
          }
        }
        :deep(.t-form__item) {
          margin-bottom: 0;
          font-size: 12px;
          .t-radio__input {
            width: 12px;
            height: 12px;
          }
        }
      }
    }
    .physical {
      padding-top: 2px;
    }
    .fictitious {
      .common-item-view {
        margin-bottom: 0;
        padding: 0;
      }
      :deep(.t-form__item) {
        height: 26px;
        display: flex;
        margin-bottom: 6px;
        font-size: 12px;
      }
      :deep(.t-form__label) {
        width: 70px;
        text-align: end;
      }
      :deep(.t-input) {
        height: 20px;
        .t-input__inner {
          font-size: 12px;
          color: #9e9e9e;
        }
      }
    }
  }

  .footer {
    height: 48px;
    padding: 5px 0 8px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
</style>
